//
//  FindCell.m
//  HubeiHotel
//
//  Created by LiBenCan on 17/11/17.
//  Copyright © 2017年 张露杰. All rights reserved.
//

#import "FindCell.h"
#import "UILabel+HWDUILabel.h"
@implementation FindCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setUpUI];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setUpUI
{
    //图片
    _producImageV = [[UIImageView alloc] init];
//    _producImageV.image = [UIImage imageNamed:@"Main_hotel"];
    [self.contentView addSubview:_producImageV];
    _producImageV.clipsToBounds = YES;
    _producImageV.contentMode = UIViewContentModeScaleAspectFill;
    [_producImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(15*screenW_6));
        make.top.equalTo(@(20*screenW_6));
        make.size.mas_equalTo(CGSizeMake( 107.5* screenW_6,75 * screenW_6));
    }];
    
    //名字
    _nameLab = [UILabel new];
    _nameLab.textColor = [UIColor colorWithHexString:@"333333"];
    _nameLab.font = [UIFont systemFontOfSize:17];
    _nameLab.textAlignment = NSTextAlignmentLeft;
//    _nameLab.text = @" ";
    _nameLab.numberOfLines = 0;
    [self.contentView  addSubview:_nameLab];
    [_nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_producImageV.mas_right).offset(10*screenW_6);
        make.top.equalTo(_producImageV.mas_top);
        make.right.equalTo(self.contentView ).offset(-10*screenW_6);
        make.height.equalTo(@(25*screenW_6));
    }];
    
    //描述 规格
    _describLab = [UILabel new];
    _describLab.textColor = [UIColor colorWithHexString:@"#999999"];
    _describLab.font = [UIFont systemFontOfSize:13.0];
    _describLab.textAlignment = NSTextAlignmentLeft;
//    _describLab.text = @" ";
    _describLab.numberOfLines = 0;
    [self.contentView  addSubview:_describLab];
    [_describLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_producImageV.mas_right).offset(10*screenW_6);
        make.right.equalTo(self.contentView ).offset(-10*screenW_6);
        make.top.equalTo(_nameLab.mas_bottom).offset(0*screenW_6);
        make.height.equalTo(@(25*screenW_6));
    }];
    
    
    
    //价格
    _priceLab = [UILabel new];
    _priceLab.textColor = [UIColor colorWithHexString:@"#ff6900"];
    _priceLab.font = [UIFont systemFontOfSize:17.0];
    _priceLab.textAlignment = NSTextAlignmentLeft;
//    _priceLab.text = @" ";
    [self.contentView  addSubview:_priceLab];
    [_priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_producImageV.mas_right).offset(10*screenW_6);
        make.height.equalTo(@(25*screenW_6));
        make.top.equalTo(_describLab.mas_bottom).offset(6);
        make.right.equalTo(self.contentView ).offset(-10*screenW_6);
    }];
    
    //画线
    _lineLab = [UILabel new];
    _lineLab.backgroundColor = LineColor;
    _lineLab.text = @" ";
    [self.contentView  addSubview:_lineLab];
    [_lineLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.height.equalTo(@1);
        make.top.equalTo(_producImageV.mas_bottom).offset(20*screenW_6);
        make.bottom.equalTo(self.contentView).offset(0);
    }];
}

-(void)setDataDic:(NSDictionary *)dataDic
{
    NSString * imageUrl = [dataDic[@"image"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    UIImage *newImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:imageUrl];//用地址去本地找图片
    if (newImage != nil) {//如果本地有
        // newImage就是图片
        _producImageV.image = newImage;
        
    } else {//如果本地没有
        //下载图片
        [[SDWebImageManager sharedManager] downloadImageWithURL:[NSURL URLWithString:imageUrl] options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) {
            //这里是处理下载进度的,好像没必要管他
        } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
            if (image) {//下载完成后
                //同上处理
                _producImageV.image = image;
            }
        }];
    }
    _nameLab.text = dataDic[@"title"];
    _describLab.text = dataDic[@"describe"];
    _priceLab.text = [NSString stringWithFormat:@"￥%@",dataDic[@"price"]];
}

@end
